﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsCrawler.Common.Interfaces;
using NewsCrawler.Common.Models;
using HtmlAgilityPack;

namespace Chip
{
    public class Parse
    {
        List<Article> ICrawler.Parse()
        {
            string html = openURL();
            html = cleanHtml(html);
            List<Article> articles = generateArticles(html);
            return articles;
        }

        private List<Article> generateArticles(string html)
        {
            List<Article> articles = new List<Article>();

            HtmlDocument doc = new HtmlDocument();
            doc.Load("file.htm");
            foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
            {
                HtmlAttribute att = link.Attributes["href"];
                if (att.Value.ToLowerInvariant().Contains("/konu/"))
                {
                    articles.Add(generateArticle(att.Value));
                }
            }

            return articles;
        }
    }
}
